package com.example.mybatis.my.shop.controller;

import com.example.mybatis.my.shop.entity.TbUser;
import com.example.mybatis.my.shop.service.TbUserService;
import com.example.mybatis.my.shop.service.impl.TbUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(value = "/userSearch")
public class UserSearchController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String, String> map = new HashMap<>();
        map.put("search",req.getParameter("search"));
        map.put("phone",req.getParameter("phone"));
        map.put("userName",req.getParameter("userName"));
        map.put("email",req.getParameter("email"));

        TbUserService tbUserService = new TbUserServiceImpl();
        List<TbUser> tbUsers = tbUserService.searchByTbUser(map);
        req.setAttribute("userList",tbUsers);
        req.getRequestDispatcher("user_list.jsp").forward(req,resp);
    }
}
